﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.EntityFrameworkCore;
using WpfApp1.Models;
using WpfApp1.ViewModels;

namespace WpfApp1 {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {

        private MainViewModel _mainViewModel;

        public MainWindow() {

            InitializeComponent();
            _mainViewModel = new MainViewModel();
            _mainViewModel.LoadCustomers();
            DataContext = _mainViewModel;
        }


        private void ClearCustomerInfo_Click(object sender, RoutedEventArgs e) {
            _mainViewModel.ClearSelectedCustomer();
        }

        private void SaveCustomer_Click(object sender, RoutedEventArgs e) {
            try {

                string name = NameTextBox.Text.Trim();
                string idNumber = IdNumberTextBox.Text.Trim();
                string address = AddressTextBox.Text.Trim();
                _mainViewModel.SaveCustomer(name, idNumber, address);
            } catch(Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddAppointment_Click(object sender, RoutedEventArgs e) {
            try {

                _mainViewModel.AddAppointment();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
